import request from "@/utils/request";

// 获取类型businessType
function getBusinessType() {
  let type = "";
  const pathname = window.location.pathname;
  if (pathname.includes("matter")) {
    type = "TODO";
  }
  if (pathname.includes("application")) {
    type = "HOLIDAY";
  }
  return type;
}

// 我的申请列表
export const getMyList = (data) => {
  const type = getBusinessType();
  console.log("type", type);
  return request({
    url: `/workflow/audit/list/${type}`,
    method: "post",
    data,
  });
};
// 我的申请新增查询
export const getDetail = (params) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/audit/info/${type}`,
    method: "get",
    params,
  });
};
// 代办详情
export const getTaskDetail = (params) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/taskinfo/info/${type}`,
    method: "get",
    params,
  });
};
// 我的申请保存
export const save = (operateType, data) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/audit/save/${operateType}/${type}`,
    method: "post",
    data,
  });
};
// 获取人员
export const getPersonnel = (params) => {
  console.log("参数", params);
  return request({
    url: "/cim/self/org/contacts",
    method: "GET",
    params,
  });
};
// 获取本部人员
export const getSelfPersonnel = (data) => {
  return request({
    url: "/cim/self/dept/contacts",
    method: "GET",
    data,
  });
};
// 附件上传
export const uploadFile = (businessId, data) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/business_attach/upload/${type}/${businessId}`,
    method: "POST",
    data,
  });
};

// 撤回
export const auditReback = (data) => {
  return request({
    url: `/workflow/audit/reback`,
    method: "POST",
    data,
  });
};

// 已审批的/代办的列表
export const getTaskinfoList = (data) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/taskinfo/pages/${type}`,
    method: "POST",
    data,
  });
};
// 待办-->处理接口
export const taskInfoSave = (operateType, data) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/taskinfo/save/${operateType}/${type}`,
    method: "POST",
    data,
  });
};
// 查询附件列表
export const getFileList = (businessId) => {
  const type = getBusinessType();
  return request({
    url: `/workflow/business_attach/list/${type}/${businessId}`,
    method: "POST",
  });
};
